const plugin = requirePlugin("taskPlugin")
var optionCpt_activePar={};   //储存活动ename与poolID
var optionCpt_optionIntervalObj=null; //计时器的变量

Component({
  mixins: [],
  data: {

		nandu:[
      {title:'难度选择',id:'userNick'},
      {title:'拼图时间',id:'prizeName'},
      {title:'获胜得分',id:'info'},
      {title:'额外积分',id:'type'}
		],
		drawData:[],

		roleText:
			'拼拼乐冲榜：\n'+
      '拼拼乐冲榜是一款拼图休闲益智游戏，用户通过拼图PK有机会获得惊喜，PK获胜增加排行榜积分，活动结束后根据游戏排名发放奖品。\n'+
      '1.活动时间：\n'+
      '2021/02/01 00:00:00 - 2021/02/07 00:00:00 \n'+
      '2.用户可邀请好友(失败则进入随机匹配)或者进入随机匹配进行拼图PK，PK获胜有机会获得奖品；\n'+
      '3.用户通过做任务可以增加游戏次数；\n'+
      '4.活动时间截至，根据排行榜排名发放奖品，请在活动结束后3天内领取奖品(打开排行榜点击领取填写地址)！超时未领取视为主动放弃；\n'+
      '5.活动最终解释权归本店铺所有。',
		
		tasktxt:[
			{title:'任务标题',id:'userNick'},
			{title:'任务次数',id:'prizeName'},
			{title:'奖励内容',id:'info'},
			{title:'操作',id:'type'}
		],

		taskList:[
			{
				tit:'关注店铺',
				num:1,
				prizeNum:'1'
      },
      {
				tit:'浏览商品',
				num:1,
				prizeNum:'1'
      },
			{
				tit:'加入会员',
				num:1,
				prizeNum:'1'
			},
			
      // {
			// 	tit:'收藏商品',
			// 	num:1,
			// 	prizeNum:'1'
      // },
      {
				tit:'分享活动',
				num:3,
        prizeNum:'1',
        shareImg:"https://img.alicdn.com/imgextra/i2/4161056916/O1CN01ebM2up20xZqoNx6cH_!!4161056916.jpg",
        title:"一起PK冲榜吧~",
        shareTextarea:"一起来跟我玩拼图PK吧~丰富奖品等你哦~"
      },
      
		],

		pkPrizeTle:[
			{
				tit:'奖品名称',
				w:15
			},
			{
				tit:'奖品图片',
				w:20
			},
			{
				tit:'对应拼图难度',
				w:10
			},
			{
				tit:'类型',
				w:10
			},
			{
				tit:'概率',
				w:10
			},
			{
				tit:'一天获得次数',
				w:10
			},
			{
				tit:'数量',
				w:10
			},
			{
				tit:'操作',
				w:15
			}
    ],


    //pk
		prizeData:[
			// {
			// 	name:'优惠券',
			// 	url:'https://img.alicdn.com/imgextra/i1/4161056916/O1CN0195Ddp720xZqJxFuRB_!!4161056916.png',
			// 	diff:'高',
			// 	type:'实物奖',
			// 	probability:50,
			// 	dayNum:1,
			// 	count:123
			// }
		],

		listPrizeTle:[
			{
				tit:'奖品名称',
				w:15
			},
			{
				tit:'奖品图片',
				w:15
			},
			{
				tit:'名次',
				w:15
			},
			{
				tit:'类型',
				w:15
			},
			{
				tit:'操作',
				w:40
			}
		],

		//排行榜奖品
		listPrize:[
			// {
			// 	name:'iphone12',
			// 	url:'https://img.alicdn.com/imgextra/i1/4161056916/O1CN0195Ddp720xZqJxFuRB_!!4161056916.png',
			// 	num:1,
			// 	type:'实物奖'
			// },
			// {
			// 	name:'iphone12',
			// 	url:'https://img.alicdn.com/imgextra/i1/4161056916/O1CN0195Ddp720xZqJxFuRB_!!4161056916.png',
			// 	num:1,
			// 	type:'实物奖'
			// }
		],

		diffList:[
			{
				title:'低',
				isEnable:0,
				difficulty:1,
				gameTime:60,
				winScore:10,
				winShareScore:10
			},
			{
				title:'中',
				isEnable:0,
				difficulty:2,
				gameTime:60,
				winScore:30,
				winShareScore:10
			},
			{
				title:'高',
				isEnable:0,
				difficulty:3,
				gameTime:60,
				winScore:50,
				winShareScore:10
			}
		],

		userDayGameTime:1,
		oldUserDayGameTime:1,
		userFollowDayGameTime:1,

		showAddTask:false,     //图片视频切换
		
		taskIdx:0,
		addTaskList:{
			tit:'每日签到',
			num:'',
			prizeNum:''
		},
		taskTxt:[
			'每日签到',
			'关注店铺',
			'加入会员',
      '浏览商品',
      '收藏商品',
      '分享活动'
		],

		bjTaskShow:false,

		bjTaskIdx:0,

		//奖品弹窗
    showAddPkPrize:false,
    
    
    //选择优惠券/实物奖品btn
		ismaterial:false, //true -- 实物奖
		
		PkPrize:{
			xu:{},
			shi:{}
		},

		showListPrize:false,
    listMaterial:true,
		addlistPrize:{
			xu:{},
			shi:{}
    },

    activeType:0,   //0-3  3--收藏商品  4-分享活动

		//powerCover:true,    // 权限覆盖
		
		showShopPop:false,   //商品弹窗

		shopArr:{
				name:'优惠券',
				url:'https://img.alicdn.com/imgextra/i1/4161056916/O1CN0195Ddp720xZqJxFuRB_!!4161056916.png',
				diff:'高',
				type:'实物奖',
				probability:50,
				dayNum:1,
				count:123
    },
    
		jihuoShop:0,

    shopArr:[],
    
		showShopPopBj:'',

		showGJShopPop:false,

		selectArrayData:[],

		selData:[],

		endSelectShopData:[],

    shareImgSize:{
      width:200,
      height:200
		},
		
		// *************************************************
		//奖品弹窗
    showAddPkPrize:false,
		isPkShi:false


	},
  props: {
    powerCover:""
  },

  onInit(){

    //my.alert({title:"appID",content:getApp().APPID});
    
    console.info('**********************************',getApp().APPID)

    this.setData({
      appid:getApp().APPID,
    })

    if(getApp().actStart && getApp().actEnd){
      this.setData({
        roleText:
        '拼拼乐冲榜：\n'+
        '拼拼乐冲榜是一款拼图休闲益智游戏，用户通过拼图PK有机会获得惊喜，PK获胜增加排行榜积分，活动结束后根据游戏排名发放奖品。\n'+
        '1.活动时间：\n'+
        ` ${getApp().actStart}- ${getApp().actEnd} \n`+
        '2.用户可邀请好友(失败则进入随机匹配)或者进入随机匹配进行拼图PK，PK获胜有机会获得奖品；\n'+
        '3.用户通过做任务可以增加游戏次数；\n'+
        '4.活动时间截至，根据排行榜排名发放奖品，请在活动结束后3天内领取奖品(打开排行榜点击领取填写地址)！超时未领取视为主动放弃；\n'+
        '5.活动最终解释权归本店铺所有。',
      })

      // getApp().actStart = '',
      // getApp().actEnd = ''

    }

  },

  didMount() {
    
    this.$page.optionCpt = this

    //my.alert({content:this.data.appid})

    //第二次进入组件清除缓存
    if(getApp().cle == 'act'){

      this.setData({

        prizeData:[],

        listPrize:[],

        PkPrize:{
          xu:{},
          shi:{}
        },

        addlistPrize:{
          xu:{},
          shi:{}
        },
        
      })

      //getApp().cle = ''

    }
    

    //引入插件
    var plugin = requirePlugin("myPlugin");

    const bridge = {

      bizCode: "3000000028703214",   //这个id需要后端传

      getCheckBenefitID({ ename, poolID }) {

        optionCpt_activePar={ "ename":ename,"poolID":poolID }

        my.navigateBack();
        
      }
    }

    plugin.setBridge(bridge);



	},
  didUpdate() {},
  didUnmount() {},
  methods: {


    inintBeforeGoto(){//跳转去权益中心前的初始化函数
      //1、清空存储ename数据的变量
      optionCpt_activePar={}
      //2、启动计时器
      optionCpt_optionIntervalObj=setInterval(()=>{
        this.handleOptionCptViewAppear()
      },500)
    },

    handleOptionCptViewAppear(){  //专门在此函数中处理权益中心返回的数据
      /*  此两个全局变量在最顶部定义
        var optionCpt_activePar={};   //储存活动ename与poolID
        var optionCpt_optionIntervalObj=null; //计时器的变量
      */
      if(optionCpt_activePar.ename){
        //关闭计时器
        clearInterval(optionCpt_optionIntervalObj)
        getApp().cloud.application.httpRequest({
          'path' : '/api/b/returnPrizeInfo', 
          'method':' POST ',
          'headers':{ "Content-Type":"application/json"},
          'body':{ ename : optionCpt_activePar.ename},
          }).then(res => {
          
            if(res.code != 200){
              my.alert({content:res.msg})
            }else{
              getApp().typee = 1
              getApp().bs11 = 1
              // 把返回数据存在缓存里面
              this.showthedatatopop(JSON.parse(res.data)[0])
              getApp().cle = ''

              
              // if(getApp().popType == 'pk'){
              //   getApp().name = ''
              //   getApp().count = ''
              //   getApp().typeidd = ''
              //   getApp().name = JSON.parse(res.data)[0].right_type_name
              //   getApp().count = JSON.parse(res.data)[0].remain_prize_quantity
              //   getApp().typeidd = JSON.parse(res.data)[0].right_type_id
              //   getApp().cle = ''
              // }else if(getApp().popType == 'list'){
              //   getApp().name = ''
              //   getApp().count = ''
              //   getApp().typeidd = ''
              //   getApp().name = JSON.parse(res.data)[0].right_type_name
              //   getApp().count = JSON.parse(res.data)[0].remain_prize_quantity
              //   getApp().typeidd = JSON.parse(res.data)[0].right_type_id
              //   getApp().cle = ''
              // }


            }
        })
      }
    },

    showthedatatopop(loterrydata){//把数据显示到添加奖品的弹窗上

      var optionCptLow = my.getStorageSync({ key: 'optionCptLow' });

      this.setData({
        ...optionCptLow.optionCptLow
      })

      this.setData({
        userDayGameTime:getApp().userDayGameTime ,
        oldUserDayGameTime:getApp().oldUserDayGameTime ,
        userFollowDayGameTime:getApp().userFollowDayGameTime ,
      })

      if(getApp().popType && getApp().popType == 'pk'){		 

        this.setData({

          PkPrize:{...this.data.PkPrize,
            xu:{...this.data.PkPrize.xu,
              name:loterrydata.right_type_name,
              count:loterrydata.remain_prize_quantity,
              url: loterrydata.right_type_id == 3 ? 'https://img.alicdn.com/imgextra/i4/4161056916/O1CN01ADQJMl20xZqgQJMPe_!!4161056916.png' : 'https://img.alicdn.com/imgextra/i3/4161056916/O1CN01E1Iu8q20xZqoLs43b_!!4161056916.png',
              ename: optionCpt_activePar.ename
            }
          }

        })

        this.setData({
          showAddPkPrize:true,
          isShowShi:false
        })

      }else if(getApp().popType && getApp().popType == 'list'){

        this.setData({

          addlistPrize:{...this.data.addlistPrize,
            xu:{...this.data.addlistPrize.xu,
              name:loterrydata.right_type_name,
              count:loterrydata.remain_prize_quantity,
              url:loterrydata.right_type_id == 3 ? 'https://img.alicdn.com/imgextra/i4/4161056916/O1CN01ADQJMl20xZqgQJMPe_!!4161056916.png' : 'https://img.alicdn.com/imgextra/i3/4161056916/O1CN01E1Iu8q20xZqoLs43b_!!4161056916.png',
              ename: optionCpt_activePar.ename
            }
          }

        })
        
        this.setData({
          showListPrize:true
        })

      }

      //my.alert({title:"显示数据",content:this.data});
    
      getApp().popType = ''

    },



    async onSubmit() {
      const res = await plugin.client.post({ path: "/task/submit" })
    },

		jiangchiJiaoC(){

			// my.navigateTo({
			// 	url: '../webView/webView?url=https://www.yuque.com/docs/share/ad926237-4115-4c24-b17b-e2334a477261?#'
			// });

			my.qn.navigateToWebPage({
				url: "https://www.yuque.com/docs/share/ad926237-4115-4c24-b17b-e2334a477261?#",
				success: res => {
				},
				fail: res => {
				}
      });
      
		},

		//多选商品组

		closeGJShopPop(){
			this.setData({
				showGJShopPop:false
			})
		},

		//任务弹窗中选择商品
		selectPR(){


			getApp().cloud.application.httpRequest({
				'path' : '/api/b/user/getMerchantOnSale', 
				'method':'get',
				'headers':{ "Content-Type":"application/json"},
				'body':{},
				}).then(res => {
					console.info("获取商家在售商品=====",res)

					if(res.code != 200){

						my.alert({content:res.msg})

						return
					}

					
					let shopArr = JSON.parse(res.data);

					let arr = []
					shopArr.map((v,i) => {
						arr.push(false)
					})

					this.setData({
						showGJShopPop:true,
						shopArr:shopArr,
						selData:arr,
						endSelectShopData:[]
					})


			})

			

		},

		//选中
		seThis(e){
			let idx = e.target.dataset.idx
			let arr = this.data.selData

			arr[idx] = !arr[idx]
			
			this.setData({
				selData:arr
			})
		},

		submitGJShop(){
			let arr = this.data.selData

			let shopData = this.data.shopArr

			let newArr=[]   //2021-02-06 03:46  累了,特此备注

			arr.map((v,i) => {
				if(v){
					newArr.push(shopData[i])
				}
			})

			this.setData({
				endSelectShopData:newArr,
				selectArrayData:[],
				selData:[],
				showGJShopPop:false
			})

			console.info(newArr)
		},

		//多选商品组


		//商品组弹窗
		closeShopPop(){
			this.setData({
				showShopPop:false
			})
		},
		//选中商品
		selectShop(e){
			let idx = e.target.dataset.idx;

			this.setData({
				jihuoShop:idx
			})
		},

		submitShop(){

			let aa = this.data[this.data.showShopPopBj];

			aa.shi =  {
				name:this.data.shopArr[this.data.jihuoShop].title,
				url:this.data.shopArr[this.data.jihuoShop].pic_url,
        type:'实物奖',

        bindNumIid : this.data.shopArr[this.data.jihuoShop].num_iid,
        // num_iid:this.data.shopArr[this.data.jihuoShop].num_iid
			}

			this.setData({
				showShopPop:false,
				[this.data.showShopPopBj]:aa
			})

			console.info(this.data.showShopPopBj)
		},

		//商品组弹窗
		diff(e){
			console.info(e)

			let idx = e.target.dataset.ind;
			let type = e.target.dataset.type;

			let val = e.detail.value;

			let lin = this.data.diffList;

			if(type == 'isEnable'){
				lin[idx][type] = val ? 0 : 1;
			}else{
				lin[idx][type] = val;
			}

			this.setData({
				diffList:lin
			})

		},

		gameNum(e){
			console.info(e)

			this.setData({
				[e.target.dataset.type]:e.detail.value
			})
			
			console.info(this.data)

    },
 
		selectChange(e){
			this.setData({
        taskIdx:e.detail.value,
        activeType:e.detail.value
			})
    },
    
    //选择宝贝 
    selectPr(){
      
    },

		//显示添加任务弹窗
		shwoAddTask(){
			this.setData({
        bjTaskShow:false,
				showAddTask:true,
				taskIdx:0,
				addTaskList:{}
			})
		},

		//关闭增加任务弹窗
		closeAddTask(){

			this.setData({
        bjTaskShow:false,
				showAddTask:false,
				taskIdx:0,
				activeType:0,
        addTaskList:{},
        // prizeData:[],
        // listPrize:[]  
			})

    },

    //分享图片
    shareImg(e){
      //console.log("1656556",e)
      let _this = this
      my.chooseImage({
        success: (images) => {

          // 判断宽高上传
          my.getImageInfo({
            src:images.apFilePaths[0],
            success:(res)=>{
              
              console.log("sfdsf",JSON.stringify(res));
              
              if(res.width != _this.data.shareImgSize.width || res.height != _this.data.shareImgSize.height){
                  my.showToast({content:"图片尺寸不符，请重新上传"})
                }else{
                  getApp().cloud.file.uploadFile({  
                    filePath: images.apFilePaths[0],  
                    fileType: 'image'
                  }).then((images)=>{    

                    let type = e.currentTarget.dataset.type;
                    let lin = _this.data.addTaskList;
                    lin[type] = images.url;
                    lin.tit = _this.data.taskTxt[_this.data.taskIdx]
                    _this.setData({
                      addTaskList:lin
                    })
                    console.log(_this.data.addTaskList)
                  })
                }
            }
          })
        },
      });
    },

		//提交添加任务
		submitAddTask(){
      
			console.info(this.data.addTaskList)

			let add = this.data.addTaskList;
			let task = this.data.taskList;

			if(this.data.bjTaskShow){
				task.splice(this.data.bjTaskIdx,1)
			}

			for(let i in task){
				if(task[i].tit == add.tit){
					my.alert({content:'该任务已存在'});
					return
				}
      }
      
      if(add.tit == '收藏商品'){
        add.num = 1
      }

			task.push(add)

			this.setData({
				taskList:task,
				addTaskList:{},
				showAddTask:false,
        bjTaskShow:false,
        activeType:0
			})

		},

		//增加任务的输入
		inpChange(e){
			let type = e.target.dataset.type;

			let lin = this.data.addTaskList;

			lin[type] = e.detail.value;
			lin.tit = this.data.taskTxt[this.data.taskIdx]

			this.setData({
				addTaskList:lin
			})

			console.info("111",this.data.addTaskList)
		},

		//任务顺序操作
		taskSwitch(e){
			let idx = e.target.dataset.idx;
			let type = e.target.dataset.type;

			let lin = JSON.parse(JSON.stringify(this.data.taskList))

			if((idx == 0 && type == 'up') || (idx == lin.length - 1 && type == 'down'))return;

			if(type == 'up'){
				
				lin.splice(idx-1,0,lin.splice(idx,1)[0]);
				
			}else{
				lin.splice(idx+1,0,lin.splice(idx,1)[0]);
			}

			this.setData({
				taskList:lin
			})
		},

		//删除任务
		del(e){
			let idx = e.target.dataset.idx;

			let lin = JSON.parse(JSON.stringify(this.data.taskList))

			lin.splice(idx,1)

			this.setData({
				taskList:lin
			})

		},

		//任务编辑
		taskEd(e){

      //判断是分享还是收藏

      let idx = e.target.dataset.idx;
      
      let data = this.data.taskList[idx];  
      
			let taskTxt = this.data.taskTxt;
			
      let index = 0;

      console.log("编辑的哪条",data);
            
			for(let z in taskTxt){
				if(taskTxt[z] == data.tit){
					index = z
				}
      }
      
      if(data.tit == '分享活动'){

        this.setData({
          activeType:5
        })

      }else if(data.tit == "收藏商品"){
        this.setData({
          activeType:4
        })
      }

			this.setData({
				showAddTask:true,
				addTaskList:data,
				taskIdx:index,
				bjTaskShow:true,
				bjTaskIdx:idx
			})

		},

		//选择实物奖
    material(){

      // console.log("优惠券和红包")
      this.setData({
        ismaterial:false
      })

    },
    //选择实物奖
    fictitious(){

      // console.log("实物奖品")
      this.setData({
        ismaterial:true
      })

    },

    //选择优惠券按钮
    // materialbtn(){

    //   my.alert({title:'pk优惠券按钮'});

    //   this.onSubmit();

    //   console.log("选择优惠券");
      
    //   getApp().typee = 1
		// 	getApp().bs11 = 1				//0 -- 1
		// 	getApp().popType = 'pk'   // pk -- list

    //   //***********	可以在这里做数据缓存了 */\

    //   getApp().userDayGameTime = this.data.userDayGameTime;
    //   getApp().oldUserDayGameTime = this.data.oldUserDayGameTime;
    //   getApp().userFollowDayGameTime = this.data.userFollowDayGameTime;
      
    //   my.setStorageSync({
    //     key: 'optionCptLow',
    //     data: this.data
    //   });

    //   console.info('asdasdasdsadadas======================>',getApp().typee)

    // },


    //选择实物奖按钮
    fictitiousbtn(){

      console.log("选择实物奖");
      
      getApp().cloud.application.httpRequest({
				'path' : '/api/b/user/getBindProductLst', 
				'method':'POST',
				'headers':{ "Content-Type":"application/json"},
				'body':{ activityId : getApp().activityId},
				}).then(res => {


					console.info("获取商家专属下单商品=====",res)

					if(res.code != 200){

						my.alert({content:res.msg})

						return
          }
        
          if(res.data != ""){

            //let data = JSON.parse(res.data);
            for(let i=0; i<res.data.length; i++){
              res.data[i].title  =  res.data[i].title.slice(0,6)
            }

            this.setData({
              showShopPop:true,
              showShopPopBj:'PkPrize',
              shopArr:data
            })

            // this.setData({
            //   showShopPop:true,
            //   showShopPopBj:'addlistPrize',
            //   shopArr:res.data
            // })

          }else{

            my.alert({
              title:"专属下单商品",
              content:"暂无专属下单商品，请前往配置",
              buttonText: '去配置',
              success: () => {
                my.qn.navigateToWebPage({
                  url: "https://haomai.taobao.com/trade_open?spm=a219a.15212435.0.0.b1ae669aDycaRX#/application",
                  success: res => {
                  },
                  fail: res => {
                  }
                })
              }
            });

          }

      });
      
       return false;
		
			getApp().cloud.application.httpRequest({
				'path' : '/api/b/user/getMerchantOnSale', 
				'method':'get',
				'headers':{ "Content-Type":"application/json"},
				'body':{},
				}).then(res => {

					console.info("获取商家在售商品=====",res)

					if(res.code != 200){

						my.alert({content:res.msg})

						return
					}

					let data = JSON.parse(res.data);

					this.setData({
						showShopPop:true,
						showShopPopBj:'PkPrize',
						shopArr:data
					})


			})

		},
		
		//关闭pk奖品弹窗
		closePkPrize(){
			this.setData({
				showAddPkPrize:false,
				ismaterial:false,
        PkPrize:{}
			})
		},

		showPKPrize(){
			this.setData({
				showAddPkPrize:true,
				ismaterial:false
			})
		},

		inpPkPrize(e){

			let lin = this.data.PkPrize
			let shi = e.target.dataset.shi

			console.info(e)
			console.info(e.target.dataset.type)

			lin[shi][e.target.dataset.type] = e.detail.value;

			this.setData({
				PkPrize:lin
			})

		},
		//PK奖品图片
		PKprizeImg(e){

			let type = e.target.dataset.type

			my.chooseImage({
				count: 1,
				success: (res) => {

					getApp().cloud.file.uploadFile({  
						filePath: res.apFilePaths[0],  
						fileType: 'image'
					}).then(ress => {
						let lin = this.data.PkPrize

						lin[type].url = ress.url;

						this.setData({
							PkPrize:lin
            })

					})
				},
			});

    },
    
    //提交pk奖品弹窗内容
		submitPkPrize(e){

      // console.info(this.data.PkPrize)
      //my.alert({content:getApp().ename})

			let type = e.target.dataset.type

			let aa = type == 'shi' ? this.data.PkPrize.shi : this.data.PkPrize.xu

			let lin = this.data.prizeData;

			aa.type = type == 'xu' ?  '虚拟奖' : '实物奖'
			aa.diff = aa.diff ? aa.diff : '低'

			aa.probability = aa.probability ? aa.probability : 50,
			aa.dayNum = aa.dayNum ? aa.dayNum : 1,
      aa.count = aa.count ? aa.count : 1

      //aa.ename = type == 'xu' &&  getApp().ename ?  getApp().ename : ''

			for(let i in lin){

				if(aa.diff == lin[i].diff){

					my.alert({
						content:'奖品难度不能相同'
					})

					return
        }
        
			}

      lin.push(aa);
      
      //my.alert({title:"提交pk奖品弹窗内容",content:JSON.stringify(lin)})

			this.setData({
				prizeData:lin,
				showAddPkPrize:false,
				ismaterial:false,
				PkPrize:{
					shi:{},
					xu:{}
				}
      })

      getApp().enmae = ''

		},

		delPkPrize(e){
			let idx = e.target.dataset.idx

			let lin = this.data.prizeData
				lin.splice(idx,1)

			this.setData({
				prizeData:lin
			})


		},
		//PK*************

		//显示排行榜奖品
		showListPrize(){
			this.setData({
				showListPrize:true
			})
		},

		//关闭排行榜奖品
		closeListPrize(){
			this.setData({
				showListPrize:false,
				addlistPrize:{
					shi:"",
					xu:""
				}
			})
		},

		inpListPrize(e){
			//判断一下填入的名称是否已存在
      for(let i in this.data.listPrize){
        if(this.data.listPrize[i].num == e.detail.value){
          this.setData({
            state:true
          })
          return 
        }else{
          this.setData({
            state:false
          })
        }
      }


			let lin = this.data.addlistPrize

			if(this.data.listMaterial){
				lin.xu[e.target.dataset.type] = e.detail.value;
			}else{
				lin.shi[e.target.dataset.type] = e.detail.value;
			}

			this.setData({
				addlistPrize:lin
			})
		},

		//选择实物奖
    listFictitious(){
      // console.log("实物奖品")
      this.setData({
        listMaterial:true
      })
    },
    //选择实物奖
    listMaterial(){
      // console.log("优惠券和红包")
      this.setData({
        listMaterial:false
      })
		},
		
		//排行榜奖品图片
		listPrizeImg(){
			my.chooseImage({
				count: 1,
				success: (res) => {

					getApp().cloud.file.uploadFile({  
						filePath: res.apFilePaths[0],  
						fileType: 'image'
					}).then(ress => {
							let lin = this.data.addlistPrize

							if(this.data.listMaterial){
								lin.xu.url = ress.url;
							}else{
								lin.shi.url = ress.url;
							}

							this.setData({
								addlistPrize:lin
							})
					})

				

				},
			});

		},

		submitAddListPrize(){

			// let aa = this.data.listMaterial ? this.data.addlistPrize.shi : this.data.addlistPrize.xu

			// let lin = this.data.listPrize;
			
			// aa.type = this.data.listMaterial ? '实物奖' : '虚拟奖'

			// lin.push(aa);

			// this.setData({
			// 	listPrize:lin,
			// 	showListPrize:false,
			// 	listMaterial:false
			// })

			let aa = this.data.listMaterial ?  this.data.addlistPrize.xu : this.data.addlistPrize.shi

			let lin = this.data.listPrize;
			
			aa.type = aa.type ? aa.type : this.data.listMaterial ? '虚拟奖' : '实物奖'

			lin.push(aa);

			this.setData({
				listPrize:lin,
				showListPrize:false,
				listMaterial:false,
				addlistPrize:{
					shi:{},
					xu:{}
				}
			})
			
		},

		clickMateria(){

      this.inintBeforeGoto();

      this.onSubmit();
    
      getApp().typee = 1
			getApp().bs11 = 1				//0 -- 1
      getApp().popType = 'list'   // pk -- list

			//***********	可以在这里做数据缓存了 */
      getApp().userDayGameTime = this.data.userDayGameTime;
      getApp().oldUserDayGameTime = this.data.oldUserDayGameTime;
      getApp().userFollowDayGameTime = this.data.userFollowDayGameTime;
      
      my.setStorageSync({
        key: 'optionCptLow',
        data: this.data
      });

      console.info('asdasdasdsadadas======================>',getApp().typee)

      my.navigateTo({ url: 'plugin://myPlugin/orightindex-page' });

      // 用于编辑回显

    },

		clickFictitious(){

			getApp().cloud.application.httpRequest({
				'path' : '/api/b/user/getBindProductLst', 
				'method':'POST',
				'headers':{ "Content-Type":"application/json"},
				'body':{activityId : getApp().activityId},
				}).then(res => {

					console.info("获取商家专属下单商品=====",res)

					if(res.code != 200){

						my.alert({content:res.msg})

            return
            
					}

					if(res.data != ""){

            //let data = JSON.parse(res.data);
            for(let i=0; i<res.data.length; i++){
              res.data[i].title  =  res.data[i].title.slice(0,6)
            }

            this.setData({
              showShopPop:true,
              showShopPopBj:'addlistPrize',
              shopArr:res.data
            })

          }else{

            my.alert({

              title:"专属下单商品",
              content:"暂无专属下单商品，请前往配置",
              buttonText: '去配置',
              success: () => {

                my.qn.navigateToWebPage({

                  url: "https://haomai.taobao.com/trade_open?spm=a219a.15212435.0.0.b1ae669aDycaRX#/application",

                  success: res => {
                  },

                  fail: res => {
                  }

                })

                
              }
            });

          }


			})

			
		},

		//排行榜奖品操作
		edListPrize(e){
			let idx = e.target.dataset.idx;
			let lin = this.data.listPrize
			if(e.target.dataset.type == 'del'){
				lin.splice(idx,1)
			}else{
				
			}

			this.setData({
				listPrize:lin
			})
		},

		// ***********************************************

		//切换实物奖-----虚拟奖
		pkPopSwitch(e){
			
			this.setData({
				isShowShi:e.target.dataset.bool == 'false' ? false : true
			})

		},

		// 点击选择PK奖品
		selctPKPrize(e){

      optionCpt_activePar={}

			let type = e.target.dataset.type

			if(type == 'shi'){
				getApp().cloud.application.httpRequest({
					'path' : '/api/b/user/getBindProductLst', 
					'method':'POST',
					'headers':{ "Content-Type":"application/json"},
					'body':{activityId : getApp().activityId},
					}).then(res => {
						console.info("获取商家专属下单商品=====",res)

						if(res.code != 200){

							my.alert({content:res.msg})

              return
              
            }
            
            if(res.data != ""){

              //let data = JSON.parse(res.data);
              for(let i=0; i<res.data.length; i++){
                res.data[i].title  =  res.data[i].title.slice(0,6)
              }

              this.setData({
                showShopPop:true,
                showShopPopBj:'PkPrize',
                shopArr:res.data
              })

            }else{

              my.alert({
                title:"专属下单商品",
                content:"暂无专属下单商品，请前往配置",
                buttonText: '去配置',
                success: () => {
                  my.qn.navigateToWebPage({
                    url: "https://haomai.taobao.com/trade_open?spm=a219a.15212435.0.0.b1ae669aDycaRX#/application",
                    success: res => {
                    },
                    fail: res => {
                    }
                  })
                }
              });

            }

				})
			}else if(type == 'xu'){

        this.inintBeforeGoto();

        this.onSubmit();

        //my.alert({title:'pk优惠券按钮'});
      
				getApp().typee = 1
				getApp().bs11 = 1				//0 -- 1
				getApp().popType = 'pk'   // pk -- list

				//***********	可以在这里做数据缓存了 */\
        console.log("sfsafsfsd",this.data)
        
        getApp().userDayGameTime = this.data.userDayGameTime;
        getApp().oldUserDayGameTime = this.data.oldUserDayGameTime;
        getApp().userFollowDayGameTime = this.data.userFollowDayGameTime;

				my.setStorageSync({
					key: 'optionCptLow',
					data: this.data
				});

        console.info('asdasdasdsadadas======================>',getApp().typee)
        my.navigateTo({ url: 'plugin://myPlugin/orightindex-page' });
        


			}

		},
	},
});
